import {
    Decimal
} from 'decimal.js';
Decimal.set({
    precision: 20,//设置精度为20位。这意味着在20位小数范围内精确显示数字。
    rounding: 4,//设置四舍五入规则为四舍五入。当输入数字在计算过程中需要保留的小数位超过20位时，根据需要进行四舍五入
    toExpNeg: -40,//负数指数的下限值
    toExpPos: 40,//正数指数的上限值
    maxE: 9e15,//设置最大指数值
    minE: -9e15,//设置最小指数值
    modulo: 1,//设置模除参数。当进行模除运算时，将保留除以模除数的余数。
    crypto: false//设置加密属性。当进行加密运算时，将返回加密后的结果。s
})
const th = function (eu) {
        let eB = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {},
            {
                decimalLength: ta = 4,
                min: tu,
                max: tc,
                commaSeparated: td
            } = eB;
        if (eu) {
            if (Number.isNaN(eu))
                return "".concat(eu);
            if (tu && Math.abs(eu) < tu)
                return "<".concat(tu);
            if (tc && Math.abs(eu) > tc)
                return ">".concat(tc);
            let eB = (0,
                rv)(eu).toDecimalPlaces(ta);
            return td ? eB.toNumber().toLocaleString() : eB.toString()
        }
        return 0 === eu ? eB.nullShow ? eB.nullShow : 0 : "--"
    },
    tg = function (eu) {
        let eB = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
        if (!eu)
            return "";
        let ta = Math.abs(eu),
            {
                acronymMin: tu = 1e2
            } = eB;
        if (!(ta >= tu) && ta >= 1)
                 return "".concat(th(ta, {
                    decimalLength: 2,
                    acronymMin:2
                }));
        if (!(ta >= tu) && ta >= 0.1)
            return "".concat(th(ta, {
                decimalLength: 4,
                acronymMin:2
            }));
        if (!(ta >= tu) && ta <= 0.1)
            return th(eu, eB);      
        if (ta >= 1e15) {
            let eu = Number(ta).toExponential().toString(),
                eB = eu.replace(/(\d+\.\d{2})(\d+)(e\+\d+)/, "$1$3");
            return eB
        }
        if (ta >= 1e12) {
            let ta = eu / 1e12;
            return "".concat(th(ta, {
                decimalLength: 0,
                ...eB
            }), "T")
        }
        if (ta >= 1e9) {
            let ta = eu / 1e9;
            return "".concat(th(ta, {
                decimalLength: 0,
                ...eB
            }), "B")
        }
        if (ta >= 1e6) {
            let ta = eu / 1e6;
            return "".concat(th(ta, {
                ...eB,
                decimalLength: 1,
            }), "M")
        }
        if (ta >= 1e3) {
            let ta = eu / 1e3;
            return "".concat(th(ta, {
                ...eB,
                decimalLength: 2,
            }), "K")
        }
    },
    ty = eu => !!Number.isNaN(eu) || null === eu || "" === eu,
    rv = eu => {
        try {
            if (ty(eu))
                return new Decimal(0);
            return new Decimal(eu)
        } catch (eu) {
            return new Decimal(0)
        }
    },
    tE = function (eu) {
        let eB = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {},
            ta = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 4;
            
        if (eu==0)
            return "0";
        if (ty(eu))
            return "";
        let tu = 1e-1,
            tc = Math.abs(eu),
            td = null;
        if (tc && tc < tu)
            td = tS(eu, ta);
        else {
            let ta = 5,
                tu = !1;
            tc >= 1e4 && tc < 1e5 && (ta = 2),
                tc >= 1e5 && (ta = 1,
                    tu = !0),
                td = tg(eu, {
                    ...eB,
                    decimalLength: ta,
                    acronymMin: 1e3,
                    commaSeparated: tu
                })
        }
        return eB.appendUSD && (td = "$".concat(td)),
            td
    },
    tS = function (eu) {
        var eB;
        let ta = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 5,
            tu = Math.abs(eu),
            tc = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉", "₁₀", "₁₁", "₁₂", "₁₃", "₁₄", "₁₅", "₁₆", "₁₇", "₁₈", "₁₉", "₂₀", "₂₁", "₂₂", "₂₃", "₂₄", "₂₅", "₂₆", "₂₇", "₂₈", "₂₉", "₃₀", "₃₁"],
            td = (0,rv)(tu).toString() || "",
            th = (null === (eB = td.split(".")[1]) || void 0 === eB ? void 0 : eB.split("")) || [],
            tg = 0;
            for (let eu = 0; eu < th.length; eu++) {
                if ("0" === th[eu])
                    tg += 1;
                else
                    break;
            }
        let ty = th.slice(tg, tg + ta).join("");
        return ty = ty.replace(/0+$/, ""),
        "".concat(eu < 0 ? "-" : "", "0.0").concat(tc[tg]).concat(ty)
    } 
export {
    tE,
}